﻿using System;
using System.Collections.Generic;
using Microsoft.DirectX.Direct3D;

namespace WolfGame {

  /// <summary>
  /// This class represents one wall in the game world
  /// </summary>
  class m_RenderableSurface {
    
    #region Member Variables

    private Common common;
    private string[] textures;
    private int animateTime;                        //how many times update is to be called before an animation happens
    private int updateCall;                         //number of times update has been called
    private int curTexIndex;                        //current texture index, if this wall animates

    #endregion

    #region Constructor

    /// <summary>
    /// Instantiate the wall
    /// </summary>
    public m_RenderableSurface(Common common) {
      this.common = common;

      // Set initial animation properties
      animateTime = 10;
      updateCall = 0;
      curTexIndex = 0;
    }

    #endregion

    #region Textures

    /// <summary>
    /// Load the textures and set the initial texture
    /// </summary>
    /// <param name="textureList"></param>
    public void LoadTextures(string textureList) {
      textures = textureList.Split(':');
      int numTextures = textures.Length;
      foreach (string s in textures) {
        common.Textures.LoadTexture(s);
      }

      Texture = common.Textures.TextureList[textures[0]];
    }

    #endregion

    #region Updates

    /// <summary>
    /// Update the texture for the wall
    /// </summary>
    public void UpdateTexture() {

      // If there is only one texture, there is no work to do
      if (textures.Length == 1)
        return;

      if (updateCall == animateTime) {
        // Time to do an update
        if (curTexIndex == textures.Length - 1)
          curTexIndex = 0;
        else
          curTexIndex++;

        updateCall = 0;
      }
      else
        updateCall++;

      Texture = common.Textures.TextureList[textures[curTexIndex]];
    }

    

    #endregion

    #region Properties

    public float X1 { get; set; }
    public float X2 { get; set; }
    public float Y1 { get; set; }
    public float Y2 { get; set; }
    public float Z1 { get; set; }
    public float Z2 { get; set; }
    public string Name { get; set; }
    public Texture Texture { get; set; }
    public int VertexToStart { get; set; }

    #endregion
  }
}